package com.thread.exe;

import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;

//构造特殊的FuturTask
public class SocketUsingTask<T> implements CancellableTask<T>{
	private Socket socket;

	public synchronized void setSockt(Socket socket) {
		this.socket = socket;
	}

	@Override
	public void cancell() {
		try {
			if(socket != null)
				socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public RunnableFuture<T> newTask() {
		return new FutureTask<T>(this) {
			@Override
			public boolean cancel(boolean mayInterruptIfRunning) {
				SocketUsingTask.this.cancell();
				return super.cancel(mayInterruptIfRunning);
			}
		};
	}

	@Override
	public T call() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}
